import list from "../../../components/list.vue"
export default {
    name: "app",
    data() {
        return {
            // 查询
            inquire: {
                userId: '',
                userName: '',
                realName: '',
            },
            // 表头
            tableColumnList: [],
            // 表格数据
            showList: [],
            // 分页数据
            page: {
                pageSize: 6,
                total: 12,
            },
            // 权限
            permissions: {
                "userId": 0,
                "userManage": false,
                "goodsManage": false,
                "inventoryManage": false,
            },
        }
    },
    components: {
        list,
    },
    created() {
        // this.$store.dispatch('get_current')

        this.search_user()
    },
    methods: {
        // 查询用户
        async search_user() {
            const inquire = this.$qs.parse(this.inquire)
            const { data: res } = await this.$http.post('/gim/api/admin/manageUser/selectUser/allUsers', inquire);
            // console.log(res)
            if (res.code == 1) {
                this.tableColumnList = res.response.tableColumnList
                this.showList = res.response.userList
                this.page.total = res.response.totalNum
                // 编辑表头
                this.$store.commit('edit_tableColumnList', this.tableColumnList)
                // 编辑表格数据
                this.$store.commit('edit_showList', this.showList)
                // 编辑分页数据
                this.$store.commit('edit_page', this.page)
                // list中改变按钮状态
                this.$store.commit('edit_isModify', this.$store.state.current.isUserManage)
                this.$store.commit('edit_isDelete', this.$store.state.current.isUserManage)
            }
            else if (res.code == 502)
                this.$store.commit('error', res.msg)
            else {
                this.showList = []
                this.total = 0
                this.$store.commit('edit_showList', this.showList)
                // 弹出错误提示
                this.$store.commit('error', res.response)
            }
        },
        // 删除用户
        async delete_user() {
            const userId = this.$store.state.Delete.row.userId
            const { data: res } = await this.$http.get('/gim/api/admin/manageUser/deleteUser/' + userId);
            if (res.code == 1) {
                this.$store.commit('success', res.response)
                this.search_user()
            }
            else
                this.$store.commit('error', res.response)
            this.$store.state.Delete.userDelete = false
        },
        // 权限管理
        async modify_user() {
            this.permissions.userId = this.$store.state.Modify.row.userId
            this.permissions.userManage = this.$store.state.Modify.row.isUserManage
            this.permissions.goodsManage = this.$store.state.Modify.row.isGoodsManage
            this.permissions.inventoryManage = this.$store.state.Modify.row.isInventoryManage

            // QS模块转化
            const permissions = this.$qs.parse(this.permissions)

            // 发送post请求
            const { data: res } = await this.$http.post('/gim/api/admin/manageUser/updateUser/managePermission', permissions);
            if (res.code == 1) {
                this.$store.commit('success', res.response)
                this.$store.state.Modify.userModify = false
            }
            else
                this.$store.commit('error', res.response)
        },
    },
};